#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGridLayout>
#include <QWidget>
#include <QResizeEvent>
#include <QCloseEvent>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QTimerEvent>
#include <QToolBar>
#include <QAction>
#include <QMessageBox>
#include <QStatusBar>
#include "titlebar.h"
#include "textedit.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(int idx, const QJsonObject &data, QWidget *parent = nullptr);

signals:
    void newWindow();
    void closeWindow();

private:
    int index;
    TextEdit *textEdit;
    QGridLayout *mainLyt;
    TitleBar *titleBar;
    QWidget *mainWidget;
    QFile *dataFile;
    QFile *qssFile;
    QString qssData;

    QStatusBar *statusBar;

    QAction *foldAction;
    QAction *linenumberAction;
    QAction *ontopAction;
    QAction *delAction;
    QToolBar *toolBar;


    QMessageBox *messageBox;

    QJsonObject confJsonObj;

    void updateWindowFromConf();
    void loadText();

private slots:
    void on_titleBar_closeWindow();

    void on_titleBar_moved(const QPoint &pos);

    void on_titleBar_expand();

    void on_titleBar_add();

    void on_titleBar_pressed();

    void on_titleBar_released();

    void on_foldAction_triggered();

    void on_linenumberAction_triggered();

    void on_ontopAction_triggered();

    void on_delAction_triggered();

    void on_textEdit_textChanged();

    void on_messageBox_buttonClicked(QAbstractButton *button);

    void resizeEvent(QResizeEvent *event);

    void closeEvent(QCloseEvent *event);

    void timerEvent(QTimerEvent *event);

public:
    QJsonObject jsonConf();
    int indexOfList();
    void setIndexOfList(int idx);
    void wShow();

};

#endif // MAINWINDOW_H
